//
//  MJTVisitorTableViewController.swift
//  swiftWeiBo
//
//  Created by MJT on 16/7/9.
//  Copyright © 2016年 MJT. All rights reserved.
//

import UIKit

class MJTVisitorTableViewController: UITableViewController {
    //定义登录标记
    var isLogin: Bool = MJTUserAccountViewModel.shareUserAccount.isLogin
    //设置访客视图
    var vistorView: MJTUIView?
    override func loadView() {
        if isLogin {
            //登录状态
            super.loadView()
        } else {
            //未登录状态
            vistorView = MJTUIView()
//            vistorView?.backgroundColor = UIColor.darkGrayColor()
            vistorView?.loginClosure = { [weak self] in
                print("访客页面的登录或注册按钮点击了")
                self?.showLoginOAuth()
            }
            view = vistorView

            setupNavUI()
        }
    }
    override func viewDidLoad() {
    }
    //设置导航栏按钮
    private  func setupNavUI() {
//        let button = UIButton()
//        button.setTitle("注册", forState: .Normal)
//        button.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
//        button.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
//        button.titleLabel?.font = UIFont.systemFontOfSize(15)
//        button.sizeToFit()
//        navigationItem.leftBarButtonItem = UIBarButtonItem(customView: button)
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "resignButtonAction")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginButtonAction")
    }
    @objc private func resignButtonAction() {
        print("注册按钮")
        showLoginOAuth()

    }
    @objc private func loginButtonAction() {
        print("登录按钮")

        showLoginOAuth()
    }
    //OAuth登录页面
    private func showLoginOAuth() {
        let OAuth = MJTOAuthViewController()
        let nav = UINavigationController(rootViewController: OAuth)
        presentViewController(nav, animated: true, completion: nil)
    }
}
